package org.dreamwork.jasmine2.javac.configuration;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2009-1-21
 * Time: 14:54:27
 */
public class ControlConfiguration implements Serializable {
    String name;
    String className;
    String defaultEvent;
    boolean template;
    private List<String> supportedEvents = new ArrayList<> ();
    private List<BindingProperty> bindProperties = new ArrayList<> ();

    public String getName () {
        return name;
    }

    public void setName (String name) {
        this.name = name;
    }

    public String getClassName () {
        return className;
    }

    public void setClassName (String className) {
        this.className = className;
    }

    public boolean isTemplate () {
        return template;
    }

    public void setTemplate (boolean template) {
        this.template = template;
    }

    public List getSupportedEvents () {
        return supportedEvents;
    }

    public void setSupportedEvents (List<String> supportedEvents) {
        this.supportedEvents = supportedEvents;
    }

    public List getBindProperties () {
        return bindProperties;
    }

    public void setBindProperties (List<BindingProperty> bindProperties) {
        this.bindProperties = bindProperties;
    }

    public String getDefaultEvent () {
        return defaultEvent;
    }

    public void setDefaultEvent (String defaultEvent) {
        this.defaultEvent = defaultEvent;
    }

    public void addEvent (String event) {
        this.supportedEvents.add (event);
    }

    public void addMapping (String attribute, String property, int type) {
        BindingProperty bp = new BindingProperty (type, attribute, property);
        bindProperties.add (bp);
    }

    public BindingProperty getBingMapByAttribute (String attribute) {
        for (BindingProperty bp : bindProperties) {
            if (bp.getAttribute ().equals (attribute)) return bp;
        }
        return null;
    }

    public BindingProperty getBingMapByProperty (String property) {
        for (BindingProperty bp : bindProperties) {
            if (bp.getProperty ().equals (property)) return bp;
        }
        return null;
    }

    public boolean equals (Object o) {
        if (this == o) return true;
        if (!(o instanceof ControlConfiguration)) return false;
        ControlConfiguration that = (ControlConfiguration) o;
        return !(bindProperties != null ? !bindProperties.equals (that.bindProperties) : that.bindProperties != null) &&
               !(className != null ? !className.equals (that.className) : that.className != null) && 
               !(name != null ? !name.equals (that.name) : that.name != null) &&
               !(supportedEvents != null ? !supportedEvents.equals (that.supportedEvents) : that.supportedEvents != null);
    }

    public int hashCode () {
        int result;
        result = (name != null ? name.hashCode () : 0);
        result = 31 * result + (className != null ? className.hashCode () : 0);
        result = 31 * result + (supportedEvents != null ? supportedEvents.hashCode () : 0);
        result = 31 * result + (bindProperties != null ? bindProperties.hashCode () : 0);
        return result;
    }
}